<?php
class Client extends Admin_Controller {

    function Client() {
        parent::Admin_Controller();
        $this->load->model('Adherent_m');
        $this->_data['listsidebar'] = 'admin/modules/client';
    }

    function index() {
        is_admin();
        $this->list_adherent();
    }


    function list_adherent(){
        is_admin();
        $per_page = $this->uri->segment(3);
        $offset = $this->uri->segment(4);
        if ($per_page == "") {
        $per_page = 10;
        }
        if ($offset == "") {
             $offset = 0;
             }
             $page="L'adherence";
             $config['base_url'] = base_url() . 'index.php/client/list_adherent' . $per_page . '/';
             $config['per_page'] = '10';
             $config['uri_segment'] = 4;
             $config['total_rows'] = $this->Adherent_m->count_adherent();
             $this->_data['query'] = $this->Adherent_m->get_adherent($config['per_page'], $offset);
             $this->pagination->initialize($config);
             $this->_data['pagination'] = $this->pagination->create_links();
             $this->_data['total'] = $config['total_rows'];
             $this->_data['page_title'] = "Gestion des adherent";
             $this->admin_view('admin/adherent/adherent');
       }
       function list_inscription(){
        is_admin();
        $per_page = $this->uri->segment(3);
        $offset = $this->uri->segment(4);
        if ($per_page == "") {
        $per_page = 10;
        }
        if ($offset == "") {
             $offset = 0;
             }
             $page="L'adherence";
             $config['base_url'] = base_url() . 'index.php/client/list_inscription' .'/'. $per_page . '/';
             $config['per_page'] = '10';
             $config['uri_segment'] = 4;
             $config['total_rows'] = $this->Adherent_m->count_inscription();
             $this->_data['query'] = $this->Adherent_m->get_inscription($config['per_page'], $offset);
             $this->pagination->initialize($config);
             $this->_data['pagination'] = $this->pagination->create_links();
             $this->_data['total'] = $config['total_rows'];
             $this->_data['page_title'] = "Gestion des adherent";
             $this->admin_view('admin/adherent/adherent');
       }

       function detail_client($id){
        is_admin();
             if ($this->input->post('submit')) {
             $debut=convertdate2($this->input->post('debut'));
              $debut =$debut.' ' . '06:00';
             $debut = human_to_unix($debut);
             $fin=convertdate2($this->input->post('fin'));
              $fin =$fin.' ' . '06:00';
             $fin = human_to_unix($fin);
             $data=array(
               'date_debut' => $debut,
               'date_fin' => $fin,
                'ad' => '1'
                    );

             $this->Adherent_m->update_client($data, $id);
             $query=$this->Adherent_m->get_detail_client($id);

             if($query['pass']==""||$query['pass']==NULL){
             $email=$query['email'];
             $string=random_string('alnum', 16);
             $stringmd5=md5($string);
             $data1 = array( 'pass'=> $stringmd5 );
             $this->Adherent_m->update_client($data1, $id);

             $get_message= $this->Adherent_m->get_mail(2);

             $message=$get_message["contenu"];
             $message=str_replace("%password%", $string, $message);

              mail($email, $get_message["titre"], $message, "From: contact@gwebcreation.com" );

             }

             }
             $query=$this->Adherent_m->get_detail_client($id);
             $this->_data['query'] = $query;

             $this->_data['sport'] = $this->Adherent_m->get_sports($query['sport']);
             $this->_data['recherche'] = $this->Adherent_m->get_recherche($query['recherche']);
             $this->_data['page_title'] = "Gestion des adherent";
             $this->admin_view('admin/adherent/detail_adherent');
       }
       function desactiver_client($id){
            $this->Adherent_m->desactiver_client($id);
            $query=$this->Adherent_m->get_detail_client($id);
            $email=$query['email'];
            $get_message= $this->Adherent_m->get_mail(3);
             mail($email, $get_message["titre"],$get_message["contenu"] , "From: contact@gwebcreation.com" );

           redirect(site_url('client/detail_client').'/'.$id);
       }
    function contact(){
        is_admin();
        $per_page = $this->uri->segment(3);
        $offset = $this->uri->segment(4);
        if ($per_page == "") {
            $per_page = 4;
        }
        if ($offset == "") {
            $offset = 0;
        }
        $config['base_url'] = base_url() . 'index.php/client/contact/' . $per_page . '/';
        $config['per_page'] = '4';
        $config['uri_segment'] = 4;
        $config['total_rows'] = $this->db->count_all('contact');
        $this->_data['query'] = $this->Adherent_m->get_contact($config['per_page'], $offset);
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
        $this->_data['total'] = $this->db->count_all('contact');
        $page="L'adherence";
        $this->_data['page_title'] = "Liste de Contact";
        $this->admin_view('admin/list_contact');
    }
    function delete_contact($id){
        $this->Adherent_m->delete_contact($id);
        redirect('client/contact'); 
    }
    function detail_contact($id){
        is_admin();
        $this->_data['query'] = $this->Adherent_m->get_detail_contact($id);
        $this->_data['page_title'] = "Gestion des contacts";
        $this->admin_view('admin/detail_contact');
    }
      
}
?>